/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jamjun.infra.web.el;

import jamjun.infra.web.el.ELBtnOpt;
import com.google.gson.Gson;
import jamjun.infra.lang.JJDate;
import jamjun.infra.lang.JJString;
import java.util.Date;
import java.util.UUID;

/**
 *
 * @author Java
 */
public class ELHelper {
    public static String jqBtn(ELBtnOpt options){
        try{
            String result="";
            if(options.color != ELColorBtn.none){
                options.classAttr = options.classAttr + " " + options.color.strValue();
            }
            
            if (options.disable == false)
            {
                result = "<span id=\"" + options.idAttr + "\" style=\"" + options.styleAttr + "\" jClick=\"" + options.onClick + "\" jIcon=\"" + options.btnIcon.jqIcon() + "\" class=\"button ElBtn " + options.classAttr + "\"  " + options.otherAttr + " >" + options.caption + "</span>";
            }
            else
            {
                result= "<span id=\"" + options.idAttr + "\" style=\"" + options.styleAttr + "\" class=\"button ElBtn disable" + options.classAttr + "\"  " + options.otherAttr + " >" + options.caption + "</span>";
            }
            return result;
        }catch(Exception e){
            throw e;
        }
    }
    
    public static String imag(String thumbImage,String fullImage,String imageGroup,ELImgOpt options){
        try{
            String result="";
            UUID obj = UUID.randomUUID();
            result = "<a href=\"" + fullImage + "?dummy=" + obj.toString() + "\" rel=\"prettyPhoto[" + imageGroup + "]\" title=\"" + options.title + "\">";
            result += "<div class=\"ShowDetail_thumbImage ImageFrame\" style=\"cursor: pointer; float:left; margin:0px 1px 0px 1px;\">";
            result += "<img src=\"" + thumbImage + "?dummy=" + obj.toString() + "\" id=\"" + options.idAttr + "\" name=\"" + options.nameAttr
                + "\" class=\"" + options.classAttr + "\" style=\"" + options.styleAttr + ";"
                + options.otherAttr
                + " onError=\"this.src='Content/Images/Image_NotAvailables.png'\" "
                + " />";
            result += "</div></a>";
            return result;    
        }catch(Exception e){
            throw e;
        }
    }
    
    public static String textBox(Integer value,ELTextboxOpt options){
        try{
            String result;
            if(value == null){
                result = "";
            }else{
                result = value.toString();
            }
            return result;    
        }catch(Exception e){
            throw e;
        }
    }
    
    public static String textBox(String value,ELTextboxOpt options){
        try{
            String result="";
            if (options.textAlign != null && options.textAlign != ELTextAlign.none)
            {
                options.classAttr += " " + options.textAlign.strValue();
            }
            String attrReadOnly = "";
            if (options.disable == true){
                attrReadOnly = " readOnly = \"readOnly\" ";
                options.classAttr += " input-readOnly "; 
            }else{
                if (options.isValidateEmpty == true)
                {
                    options.classAttr += " ui-require-field validate ";
                }
            }
            if(JJString.IsNullOrEmty(value)){
                value="";
            }
            
            result = "<input type=\"text\" id=\"" + options.idAttr + "\" name=\"" + options.nameAttr + "\" style=\"" 
                    + options.styleAttr + "\" class=\"  " + options.classAttr + "\" " + options.otherAttr 
                    + " value=\"" + value + "\" "+attrReadOnly+"  " + options.strTabIndex() + "  />";
            return result;    
        }catch(Exception e){
            throw e;
        }
    }
    
    public static String datePicker(Date value,ELDatePickerOpt options){
        try{
            String result;
            if(value == null){
                result ="";
            }else{
                //convert
                result = JJDate.ConvertToStr(value);
            }
            result = ELHelper.datePicker(result, options);
            return result;  
        }catch(Exception e){
            throw e;
        }
    }
    
    public static String datePicker(String value,ELDatePickerOpt options){
        try{
            String result="";
            if (JJString.IsNullOrEmty(value))
            {
                value = "";
            }
            if (options.isValidateEmpty == true)
            {
                options.classAttr += " ui-require-field validate ";
            }
            if(JJString.IsNullOrEmty(value)){
                value="";
            }
            if (options == null) { options = new ELDatePickerOpt(); }
            result = "<input type=\"text\" id=\"" + options.idAttr + "\" name=\"" + options.nameAttr
                + "\" style=\"" + options.styleAttr + "\"  class=\" pickdate " + options.classAttr + "\" "
                + " mindate='" + (options.minDate == null ? "" : options.minDate.toString()) + "' "
                + " maxdate='" + (options.maxDate == null ? "" : options.maxDate.toString()) + "' "
                + " yearRange='" + options.yearRange + "' "
                + " OnChange='" + options.onChange + "' "
                + options.otherAttr + " value=\"" + value + "\" defaultval=\"" + value + "\" />";
            return result;  
        }catch(Exception e){
            throw e;
        }
    }
    
    public static String numeric(Integer value,ELTextboxOpt options){
        try{
            String result="";
            return result;    
        }catch(Exception e){
            throw e;
        }
    }
    
    public static String label(String value,ELLabelOpt options){
        try{
            String result;
            if (options.textAlign != null && options.textAlign != ELTextAlign.none)
            {
                options.classAttr = options.classAttr + " " + options.textAlign.strValue();
            }
            
            result = "<label for=\"" + options.forAttr + "\" style=\"display:inline-block;" 
                    + options.styleAttr + "\" class=\"" + options.classAttr + "\" " + options.otherAttr 
                    + ">" + value + "</label>";
            return result;    
        }catch(Exception e){
            throw e;
        }
    }
    
    public static String select(String value,ELSelectOpt options,jamjun.infra.web.Json data){
        try{
            String result="";
            //<editor-fold desc="convert json to string">
            Gson gson = new Gson();
            String sJSON = gson.toJson(data.getObj());
            //</editor-fold>
            String validateEmpty = "";
            if (options.isValidateEmpty == true)
            {
                validateEmpty = "ui-require-field validate";
            }
            if(JJString.IsNullOrEmty(value)){
                value="";
            }
            result = "<select id=\"" + options.idAttr + "\" name=\"" + options.nameAttr + "\" style=\"" + options.styleAttr + "\""
                + " class=\" isGetDataFromEl " + validateEmpty + " " + options.classAttr + "\" " + options.otherAttr
                + " value1=\"" + value + "\" hasSelectListData=\"true\""
                + " onChange=\"" + options.onChange + "\" callBack=\"" + options.callBack + "\" DefaultVal=\"" + value + "\" />";
            result += "</select>";
            result += "<input type='textbox' class='selectListData' value='" + sJSON + "' style='display:none'>";
            return result;    
        }catch(Exception e){
            throw e;
        }
    }
}
